home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-24 | 3.5 KB | 134 lines | [TEXT/MSET] |
- \ serial - async serial driver support
- \ 2/04/85 cbd Version 1
- \ 9/04/86 cdn Eliminated redundant readnw: & writenw
- \ 9/06/86 cdn Added bi-directional port usage
- \ Automatically send reset: in open:
- \ 4/19/89 rfl added break:
- \ 6/13/89 rfl requires interval for pause
- \ 3/14/90 rfl added buffer:
- \ 8/16/90 rfl added baudrate: and XON:
-
- \ May 93 mrh Mops version.
-
- need drvr
-
- decimal
-
- \ define serial i/o port object
-
- :class PORT super{ PBDrvr }
- record
- { int thePort \ 0=modem, 1=printer
- int Direction \ 0=input, 1=output, 2=both
- int Config \ bits, parity, speed
- int inRef \ input IORefNum
- int outRef \ output IORefNum
- }
-
- :m INIT: \ ( port# direction -- )
- put: direction put: thePort ;m
-
- :m SETCONFIG: \ ( config -- ) Set the config word directly
- put: config ;m
-
-
- :m CONFIG: { stop data parity -- }
- \ Sets stop, data bits in the config word
- \ stop can be 1 or 2
- \ data can be 7 or 8
- \ parity: 0=none 1=odd 2=even
-
- data 7 =
- IF $ 400 ELSE $ C00 THEN -> data
- stop 1 =
- IF $ 4000 ELSE $ C000 THEN -> stop
- parity
- NIF $ 2000
- ELSE parity 1 =
- IF $ 1000
- ELSE $ 3000
- THEN
- THEN -> parity
- get: config $ 01FF and data or stop or parity or
- put: config ;m
-
-
- :m BAUD: \ ( n -- ) Sets the baud rate for the port
- \ - 300,600,1200,2400, etc.
- dup 300 =
- IF 80 +
- ELSE 300 / 380 swap / 1-
- THEN get: config $ FE00 and or put: config ;m
-
-
- :m CONTROL: \ Does PBControl call
- get: direction dup 0= swap 2 = or
- IF get: inRef put: IORefNum addr: header call PBControlSync THEN
- get: direction
- IF get: outRef put: IORefNum addr: header call PBControlSync THEN
- ;m
-
-
- :m RESET: \ Sets the communication parms from the configuration word
- 8 put: csCode get: config put: csp1 0 put: IOComp
- control: self ;m
-
-
- :m OPN: \ ( addr len -- RefNum )
- name: super open: super drop get: IORefNum ;m
-
-
- :m OPEN: \ ( -- ) Opens the read and write drivers for a port
- get: thePort
- NIF get: direction dup 0= swap 2 = or
- IF " .AIn" opn: self put: inRef THEN
- get: direction
- IF " .AOut" opn: self put: outRef THEN
- ELSE get: direction dup 0= swap 2 = or
- IF " .BIn" opn: self put: inRef THEN
- get: direction
- IF " .BOut" opn: self put: outRef THEN
- THEN
- get: IOResult reset: self ;m
-
-
- :m READ: \ ( addr len -- fcode ) receive LEN bytes on the serial port
- 0 put: IOComp get: inRef put: IORefNum read: super ;m
-
- :m WRITE: \ ( addr len -- fcode ) send LEN bytes on the serial port
- 0 put: IOComp get: outRef put: IORefNum write: super ;m
-
- :m READNW: \ ( cfa:proc addr len ) receive LEN bytes asynchronously on the port
- get: inRef put: IORefNum readnw: super ;m
-
- :m WRITENW: \ ( cfa:proc addr len ) send LEN bytes asynchronously on the port
- get: outRef put: IORefNum writenw: super ;m
-
- :m GET: \ ( -- char ) get a single character from port
- pad 1 read: self drop pad c@ ;m
-
- :m PUT: \ ( char -- ) send a single char to port
- pad c! pad 1 write: self drop ;m
-
- :m CTS: \ ( bool -- fcode ) turn CTS handshaking on or off via CONTROL call
- addr: csp1 10 erase put: csp1 10 put: csCode 0 put: IOComp
- control: self get: IOResult ;m
-
-
- :m XON: ( -- )
- 10 put: cscode $ 01001113 addr: csP1 ! control: self ;m
-
- :m BREAK: \ sends out a 100 msec break
- 12 put: csCode control: self 6 pause 11 put: csCode control: self ;m
-
- :m BUFFER: \ ( addr len -- ) increase internal buffer size from default
- \ of 64 bytes
- addr: IOBuffer w! addr: csP1 ! 9 put: cscode
- control: self ;m
-
-
- :m BAUDRATE: ( n --)
- 13 put: cscode put: csP1 control: self ;m
-
- ;class
-